package com.tb.ClassSchedule;


import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
 * Created by 汪贵春 on 2016/7/20.
 */
public class LessonViewForWeek extends FrameLayout implements View.OnClickListener{

    private Lesson lesson;
    private boolean isVoid;
    private int color;


    public LessonViewForWeek(Context context, Lesson lesson, boolean notTime) {
        super(context);
        this.lesson = lesson;
        LayoutInflater.from(context).inflate(R.layout.class_view_week,this);
        TextView content = (TextView) findViewById(R.id.text);

        String str = lesson.getName() + "@" + lesson.getAddress();
        content.setText(str);

        if(lesson.getName().equals("—") || lesson.getName().equals(" ") || lesson.getName().equals("占位")){
            isVoid = true;
        }

        if(isVoid){
            content.setAlpha(0);
        }else if (notTime){
            content.setTextColor(Color.WHITE);
            content.setBackgroundColor(Color.GRAY);
        }else{
            int r = (int)(Math.random() * 130) + 125;
            int g = (int)(Math.random() * 130) + 125;
            int b = (int)(Math.random() * 130) + 125;
            color = Color.rgb(r,g,b);
            content.setBackgroundColor(color);

        }

        if(!isVoid){
            setOnClickListener(this);
        }


    }

    @Override
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("LessonInfo",lesson);

        Intent intent = new Intent(MainActivity.main,LessonViewActivity.class);
        intent.putExtras(bundle);
        intent.putExtra("Color",color);
        MainActivity.main.startActivity(intent);

    }
}
